import { useEffect } from 'react';

interface ITypeProps {
  user_id: number;
  server_id: number;
}

export function useWebscoket(
  { user_id, server_id }: ITypeProps,
  cb: (ws: WebSocket) => void
) {
  useEffect(() => {
    const ws = new WebSocket(
      `ws://124.221.74.149:8003/koa/ws?user_id=${user_id}&server_id=${server_id}`
    );
    ws.onopen = () => {
      console.log('open', '服务器已经建立了链接');
      cb && cb(ws);
    };
  }, []);
}
